package com.usretyn.game;

import static com.usretyn.game.Constants.BOX_SIZE;

/**
 * 小九宫格
 * @author sunjf
 * @since 2021/8/19 14:34
 */
public class Grid {
    /**
     * grid 行号
     */
    private final int row;
    /**
     * grip 列号
     */
    private final int col;
    /**
     * grid 所在小九宫序号
     */
    private final int boxIndex;

    /**
     * grid 所在小九宫行号
     */
    private final int boxRow;
    /**
     * grid 所在小九宫列号
     */
    private final int boxCol;


    /**
     * grid 所在小九宫列号
     */
    private final int boxMinRow;
    /**
     * grid 所在小九宫列号
     */
    private final int boxMaxRow;

    /**
     * grid 所在小九宫列号
     */
    private final int boxMinCol;

    /**
     * grid 所在小九宫列号
     */
    private final int boxMaxCol;

    private Coordinate coordinate;

    public Grid(int row, int column){
        this(new Coordinate(row,column));
    }

    public Grid(Coordinate coordinate) {
        this.coordinate = coordinate;
        this.row = coordinate.getRow();
        this.col = coordinate.getCol();
        SudokuUtils.check(row, col);
        this.boxRow = row / BOX_SIZE ;
        this.boxCol = col / BOX_SIZE;
        this.boxIndex = this.boxRow * BOX_SIZE + this.boxCol;
        this.boxMinRow= this.boxRow * BOX_SIZE;
        this.boxMaxRow = this.boxMinRow + BOX_SIZE -1;
        this.boxMinCol = this.boxCol * BOX_SIZE;
        this.boxMaxCol = this.boxMinCol + BOX_SIZE -1;
    }

    public Coordinate getCoordinate() {
        return coordinate;
    }

    public void setCoordinate(Coordinate coordinate) {
        this.coordinate = coordinate;
    }

    public int getRow() {
        return row;
    }


    public int getCol() {
        return col;
    }


    public int getBoxIndex() {
        return boxIndex;
    }


    public int getBoxRow() {
        return boxRow;
    }


    public int getBoxCol() {
        return boxCol;
    }


    public int getBoxMinRow() {
        return boxMinRow;
    }

    public int getBoxMaxRow() {
        return boxMaxRow;
    }

    public int getBoxMinCol() {
        return boxMinCol;
    }


    public int getBoxMaxCol() {
        return boxMaxCol;
    }


    @Override
    public String toString() {
        return "Grid{" +
                "row=" + row +
                ", col=" + col +
                ", boxIndex=" + boxIndex +
                ", boxRow=" + boxRow +
                ", boxCol=" + boxCol +
                ", boxMinRow=" + boxMinRow +
                ", boxMaxRow=" + boxMaxRow +
                ", boxMinCol=" + boxMinCol +
                ", boxMaxCol=" + boxMaxCol +
                '}';
    }
}
